#include "btform.h"
#include "ui_btform.h"
#include<QMouseEvent>
btForm::btForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::btForm)
{
    ui->setupUi(this);

    // 设置line1的动画效果
     line1Animal = new QPropertyAnimation(ui->line1, "geometry", this);
     line1Animal->setDuration(1500);
     line1Animal->setKeyValueAt(0, QRect(0, 15, 2, 0));
     line1Animal->setKeyValueAt(0.5, QRect(0, 0, 2, 15));
     line1Animal->setKeyValueAt(1, QRect(0, 15, 2, 0));
     line1Animal->setLoopCount(-1);
     line1Animal->start();

     // 设置line2的动画效果
     line2Animal = new QPropertyAnimation(ui->line2, "geometry", this);
     line2Animal->setDuration(1600);
     line2Animal->setKeyValueAt(0, QRect(7, 15, 2, 0));
     line2Animal->setKeyValueAt(0.5, QRect(7, 0, 2, 15));
     line2Animal->setKeyValueAt(1, QRect(7, 15, 2, 0));
     line2Animal->setLoopCount(-1);
     line2Animal->start();

     // 设置line3的动画效果
     line3Animal = new QPropertyAnimation(ui->line3, "geometry", this);
     line3Animal->setDuration(1700);
     line3Animal->setKeyValueAt(0, QRect(14, 15, 2, 0));
     line3Animal->setKeyValueAt(0.5, QRect(14, 0, 2, 15));
     line3Animal->setKeyValueAt(1, QRect(14, 15, 2, 0));
     line3Animal->setLoopCount(-1);
     line3Animal->start();

     // 设置line4的动画效果
     line4Animal = new QPropertyAnimation(ui->line4, "geometry", this);
     line4Animal->setDuration(1800);
     line4Animal->setKeyValueAt(0, QRect(21, 15, 2, 0));
     line4Animal->setKeyValueAt(0.5, QRect(21, 0, 2, 15));
     line4Animal->setKeyValueAt(1, QRect(21, 15, 2, 0));
     line4Animal->setLoopCount(-1);
      line4Animal->start();
      clearBg();
      showAnimal();
      getId();
}
void btForm::seticon(QString btIcon, QString btText, int mid)
{
    //设置自定义按钮的图片、文字、以及id
    ui->btIcon->setPixmap(QPixmap(btIcon));
    ui->btText->setText(btText);
    this->id = mid;
}
void btForm::mousePressEvent(QMouseEvent *event)
 {
    // 告诉编译器不要触发警告
    (void)event;
    // ⿏标点击之后，背景变为绿⾊，⽂字变为⽩⾊
    ui->btStyle->setStyleSheet("#btStyle{ background:rgb(30,206,154);}*{color:#F6F6F6;}");
    emit click(this->id);// 发送⿏标点击信号
}
void btForm::clearBg()
{
    //清除上一个按钮点击的背景效果，恢复之前的样式
    ui->btStyle->setStyleSheet("#btStyle:hover{ background:#D8D8D8;} ");
}
int btForm::getId()
{
    return id;
}

void btForm::showAnimal()
{
    ui->lineBox->show();
}
btForm::~btForm()
{
    delete ui;
}
